from selenium.webdriver.common.by import By
import DBUtils
import BankCard
import CZ
import time


class TestBankCard:

    def test_bankcard1(self):

        driver = BankCard.bankCard1('lisi','123456','伊朗中央银行','1234567891548796')
        # 新增银行卡操作

        result2 = driver.find_element(By.XPATH,"//div[@class='card-body']/h4[2]").text
        # 账户余额：20116.20元
        result = result2[result2.find('：')+1:result2.find('元')]

        sql = 'select * from bankcard where cardBank = %s and cardNum = %s'
        params = ['伊朗中央银行','1234567891548796']
        data = DBUtils.select(sql,params)

        if result == '10000.00' and len(data) == 1:
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard1.png')

        assert result == '10000.00' and len(data) == 1

        driver.quit()
        time.sleep(1)
        CZ.cz3('伊朗中央银行','1234567891548796')
        # 删除卡操作


    def test_bankcard2(self):

        driver = BankCard.bankCard1('lisi', '123456', '伊拉克国民银行', '12345678915487967')

        bankCards = driver.find_elements(By.XPATH,"//div[@class='container-fluid']/div/div[not(@class)]")
        # 银行卡的数量
        time.sleep(1)
        CZ.cz3('伊拉克国民银行', '12345678915487967')
        if len(bankCards) == 0:
            print('通过')
        else:
            print('不通过')

        driver.quit()

        assert len(bankCards) == 0


    def test_bankcard3(self):


        CZ.cz5('中国人民银行','1','1234567891548796','1','10000',0)
        time.sleep(1)

        driver = BankCard.bankCard1('lisi', '123456', '伊拉克国民银行', '1234567891548796')

        bankCards = driver.find_elements(By.XPATH,"//div[@class='container-fluid']/div/div[not(@class)]")
        # 银行卡的数量
        time.sleep(1)
        CZ.cz4('1234567891548796')

        if len(bankCards) == 1:
            # 原本那张银行卡
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard3.png')

        driver.quit()

        assert len(bankCards) == 1


    def test_bankcard4(self):

        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 0)
        time.sleep(1)

        driver = BankCard.bankCard2('lisi', '123456', '伊拉克国民银行', '1234567891548796')

        bankCards = driver.find_elements(By.XPATH,"//div[@class='container-fluid']/div/div[not(@class)]")
        # 银行卡的数量
        time.sleep(1)
        CZ.cz4('1234567891548796')

        if len(bankCards) == 1:
            # 原本那张银行卡
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard4.png')

        driver.quit()

        assert len(bankCards) == 1


    def test_bankcard5(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)

        obj = BankCard.bankCard3('lisi',123456,1)
        driver,preBankNum = obj[0],obj[1]
        cur_cards = BankCard.getBankNum(driver)
        # 统计银行卡数量v

        if len(cur_cards) + 1 == preBankNum:
            print('通过')
        else:
            print('不通过')

        assert len(cur_cards) + 1 == preBankNum

        driver.quit()

    def test_bankcard6(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)
        time.sleep(1)
        obj = BankCard.bankCard3('lisi', 123456, 2)
        driver, preBankNum = obj[0], obj[1]
        cur_cards = BankCard.getBankNum(driver)
        time.sleep(1)
        CZ.cz4('1234567891548796')
        if len(cur_cards) == preBankNum:
            print('通过')
        else:
            print('不通过')

        assert len(cur_cards) == preBankNum

        driver.quit()


    def test_bankcard7(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)
        time.sleep(1)
        obj = BankCard.bankCard4('lisi','123456','中国建设银行')
        driver,preName,curName = obj[0],obj[1],obj[2]

        time.sleep(1)
        CZ.cz4('1234567891548796')
        if curName.find(preName) != -1:
            # 修改之后的银行卡名 和 没有修改之前银行卡 进行比较
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard7.png')

        assert curName.find(preName) != -1

        driver.quit()


    def test_bankcard8(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)
        time.sleep(1)
        obj = BankCard.bankCard5('lisi', '123456', '1234567891054312')
        driver,preCard,curCard = obj[0],obj[1],obj[2]
        time.sleep(1)
        CZ.cz4('1234567891054312')
        if curCard.find(preCard) == -1:
            # 修改之后的银行卡号 和 没有修改之前银行卡号 进行比较
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard8.png')

        assert curCard.find(preCard) == -1

        driver.quit()


    def test_bankcard9(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)
        time.sleep(1)
        obj = BankCard.bankCard5('lisi', '123456', '12345678910543121')
        driver, preCard, curCard = obj[0], obj[1], obj[2]
        time.sleep(1)
        CZ.cz4('12345678910543121')
        if curCard.find(preCard) != -1:
            # 修改之后的银行卡号 和 没有修改之前银行卡号 进行比较
            print('通过')
        else:
            print('不通过')
            driver.save_screenshot('test_bankcard9.png')

        assert curCard.find(preCard) != -1

        driver.quit()

    def test_bankcard10(self):
        CZ.cz5('中国人民银行', '1', '1234567891548796', '1', '10000', 1)
        time.sleep(1)

        driver = BankCard.bankCard6('lisi','123456')
        cards = BankCard.getBankNum(driver)

        bankCard_name = cards[0].find_element(By.XPATH,'./div/div/div/h4').text

        time.sleep(1)
        CZ.cz4('1234567891548796')
        if bankCard_name.find('信用卡') != -1:
            print('通过')
        else:
            print('不通过！')

        assert bankCard_name.find('信用卡') != -1

        driver.quit()
